package com.mrent.service;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;

import org.springframework.stereotype.Component;

import com.mrent.entity.OrderGoods;

@Component
public class OrderGoodsServiceImpl implements OrderGoodsService {
	
	/**
	 * 保存订单商品.
	 * 
	 * @param orderGoods
	 */
	public void saveOrderGoods(OrderGoods orderGoods){
		EntityManager em = EMF.getEM();
		EntityTransaction trans = em.getTransaction();
		try{
			trans.begin();
			em.persist(orderGoods);
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			trans.commit();
		}
	}
	
	/**
	 * 订单商品列表.
	 * @param orderNo
	 * @return
	 */
	public List<OrderGoods> listOrderGoods(String orderNo){
		EntityManager em = EMF.getEM();
		String jql = "select from OrderGoods orderGoods where orderGoods.orderNo=:orderNo";
		Query query = em.createQuery(jql);
		query.setParameter("orderNo", orderNo);
		return query.getResultList();
	}
	
	

}
